home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 32
/
Mac Magazin and MacEasy Magazine CD - Issue 32.iso
/
Multimedia
/
PlayerPRO 4.5.5 Dev.Kit
/
Plug-Ins
/
Digital Editor Plugs
/
FadeVol.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-23
|
4KB
|
171 lines
/* Fade In Vol */
/* v 1.0 */
/* 1995 by ANR */
// Usage:
// A small example of to use Digital Editor Plugs with a MODAL DIALOG
#include "MAD.h"
#include "PPPlug.h"
#if defined(powerc) || defined(__powerc)
enum {
PlayerPROPlug = kCStackBased
| RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Pcmd*)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( PPInfoPlug*)))
};
ProcInfoType __procinfo = PlayerPROPlug;
#else
#include <A4Stuff.h>
#endif
void GetDText (DialogPtr dlog, short item, StringPtr str)
{
Handle itemHandle;
short itemType;
Rect itemRect;
GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
GetIText (itemHandle, str);
}
void SetDText (DialogPtr dlog, short item, Str255 str)
{
Handle itemHandle;
short itemType;
Rect itemRect;
GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
SetIText (itemHandle, str);
}
GDHandle TheGDevice:0xCC8;
void AutoPosition( DialogPtr aDia)
{
Point Position, mouse;
Rect ViewRect;
short XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
GetMouse( &mouse);
LocalToGlobal( &mouse);
SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
(*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
Position.h = mouse.h - XSize/2;
if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
Position.v = mouse.v - YSize/2;
if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
MoveWindow( aDia, Position.h, Position.v, false);
ShowWindow( aDia);
}
Cmd* GetCmd( short row, short track, Pcmd* myPcmd)
{
if( row < 0) row = 0;
else if( row >= myPcmd->length) row = myPcmd->length -1;
if( track < 0) track = 0;
else if( track >= myPcmd->tracks) track = myPcmd->tracks -1;
return( &(myPcmd->myCmd[ (myPcmd->length * track) + row]));
}
OSErr main( Pcmd *myPcmd,
PPInfoPlug *thePPInfoPlug)
{
DialogPtr myDia;
short itemHit;
Str255 tStr;
#ifndef powerc
long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
#endif
myDia = GetNewDialog( 128, 0L, (WindowPtr) -1L);
SetPort( myDia);
AutoPosition( myDia);
SetDText( myDia, 3, "\p0");
SetDText( myDia, 4, "\p100");
SelIText( myDia, 3, 0, 200);
do
{
RESTART:
#if defined(powerc) || defined(__powerc)
ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
#else
ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
#endif
}while( itemHit != 1 && itemHit != 2);
if( itemHit == 1)
{
short track, row;
long from, to;
Cmd *myCmd;
GetDText( myDia, 3, tStr); StringToNum( tStr, &from);
GetDText( myDia, 4, tStr); StringToNum( tStr, &to);
// Check values
if( from < 0 || from > 100)
{
SelIText( myDia, 3, 0, 200);
SysBeep( 1);
goto RESTART;
}
if( to < 0 || to > 100)
{
SelIText( myDia, 4, 0, 200);
SysBeep( 1);
goto RESTART;
}
// Re-adjust val % -> 0...64
to = (to * 64) / 100;
from = (from * 64) / 100;
for( track = 0; track < myPcmd->tracks; track++)
{
for( row = 0; row < myPcmd->length; row++)
{
myCmd = GetCmd( row, track, myPcmd);
myCmd->ins = myCmd->ins; // is this very usefull ?
myCmd->note = myCmd->note; // is this very usefull ?
myCmd->cmd = myCmd->cmd; // is this very usefull ?
myCmd->arg = myCmd->arg; // is this very usefull ?
if( myPcmd->length > 1) // no zero div !!
myCmd->vol = 0x10 + from + ((to-from) * row) / (myPcmd->length-1);
// my fade command : 0x10 min vol, 0x50 : max vol
// Refer to MAD description for more informations
}
}
}
DisposDialog( myDia);
#ifndef powerc
SetA4( oldA4);
#endif
return noErr;
}